package zwp.exercise.service.exercisedemo.chapterFour;

/**
 * @Author zwp14
 * @create 2025/11/11 22:10
 * @description 计算细胞分裂到第十代的数量
 */
public class CellDivisionExerciseDemo {
    public static void main(String[] args) {
        long cellNum = 1;
        firstMethod(cellNum);

        System.out.println("方法分割符！！！");

        secondMethod(cellNum);


    }

    private static void secondMethod(long cellNum) {
        long currentTimeMillis = System.currentTimeMillis();
        for (int i = 1; i <= 10; i++) {
            System.out.printf("第%d代细胞数量%d%n",i,cellNum);
            cellNum *= 2;
        }
        // 需要注意的是这里用到了printf，需要解析格式字符串（如 %d、%n），并动态构造输出内容，这比简单的字符串拼接（+）更耗时。
        long time = System.currentTimeMillis() - currentTimeMillis;
        System.out.printf("耗时：%d", time/1000);
    }

    private static void firstMethod(long cellNum) {
        long currentTimeMillis = System.currentTimeMillis();
        for (int i = 1; i <= 10; i++) {
            if (i == 1 ){
                System.out.println("第" + i + "代细胞数量：" + cellNum);
                continue;
            }
            cellNum *= 2;
            System.out.println("第" + i + "代细胞数量：" + cellNum);
        }
        long time = System.currentTimeMillis() - currentTimeMillis;
        System.out.printf("耗时：%d", time/1000);
    }
}
